import Vue from 'vue'
import VueRouter from 'vue-router'

//发现音乐
import IndexView from '../views/discovering_music/Index.vue'

import RecommendView from '../views/discovering_music/Recommend.vue'
import ToplistView from '../views/discovering_music/Toplist.vue'
import PlaylistView from '../views/discovering_music/playlist/PlayListIndex.vue'
import DjradioView from '../views/discovering_music/Djradio.vue'
import ArtistView from '../views/discovering_music/Artist.vue'
import AlbumView from '../views/discovering_music/Album.vue'

//我的音乐
import MyView from '../views/my_music/Login.vue'
//关注
import FriendView from '../views/interest_friend/InterestPage.vue'
//下载客户端
import DownloadView from '../views/download/DownloadPage.vue'


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)
const routes = [

    //发现音乐
    {
        path: '/find',
        name: 'find',
        text: '发现音乐',
        component: IndexView,
        children: [
            {
                path: 'recommend',
                name: 'recommend',
                text: '推荐',
                component: RecommendView
            },
            {
                path: 'toplist',
                name: 'toplist',
                text: '排行榜',

                component: ToplistView
            },
            {
                path: 'playlist',
                name: 'playlist',
                text: '歌单',
                component: PlaylistView,

            },
            {
                path: 'djradio',
                name: 'djradio',
                text: '主播电台',

                component: DjradioView
            },
            {
                path: 'artist',
                name: 'artist',
                text: '歌手',

                component: ArtistView
            },
            {
                path: 'album',
                name: 'album',
                text: '新碟上架',

                component: AlbumView
            },
            {
                path: '/find',
                redirect: '/find/recommend'
            }
        ]
    },
    //我的音乐
    {
        path: '/my',
        name: 'my',
        text: '我的音乐',
        component: MyView,
    },
    //关注
    {
        path: '/friend',
        name: 'friend',
        text: '关注',

        component: FriendView
    },

    {
        path: '/download',
        name: 'download',
        text: '下载客户端',
        component: DownloadView
    },
    //重定向，默认主页面为redirect的地址
    {
        path: '/',
        redirect: '/find/recommend'
    },

]
const router = new VueRouter({
    routes
})



router.beforeEach((to,from,next)=>{
    console.log('进入路由',to,from)
    next()
})
router.afterEach((to,from)=>{
    console.log('离开路由',to,from)
})

export default router